package util

import (
	"context"
	"godesk/app/model"

	"github.com/wailsapp/wails/v2/pkg/runtime"
)

type DbUtil struct {
	ctx  context.Context
	util *Util
}

func NewDbUtil(ctx *context.Context) *DbUtil {
	u := NewUtil(*ctx)
	return &DbUtil{
		ctx:  *ctx,
		util: u,
	}
}

func (d *DbUtil) Run() {
	//创建默认类别
	category := &model.Category{
		ID:   "10086",
		Name: "未分类",
	}

	//类别存入数据库
	if err := d.util.Db().Save(&category).Error; err != nil {
		runtime.LogErrorf(d.ctx, "创建类别失败: %v", err)
		return
	}
}
